//
//  PAPersonalCenterView.m
//  PAMobileWallet
//
//  Created by shen pu on 13-7-14.
//  Copyright (c) 2013年 Say_smp002. All rights reserved.
//

#import "PAPersonalCenterView.h"
#import "PAHomePageViewController.h"
#import "PADataCenter.h"
#import "PASelfInfo.h"
#import "PAUserInfo.h"
#import "PAAsynImageView.h"
#import <QuartzCore/QuartzCore.h>
#import "UIColor+Extend.h"

@interface PAPersonalCenterView ()

@end

@implementation PAPersonalCenterView
@synthesize yueValueLabel;
@synthesize addCardButton;
@synthesize headPicButton;
@synthesize changePicButton;
//@synthesize circleHeadImage;
@synthesize headIV              = _headIV;
@synthesize rechargeButton;
@synthesize extractButton;
@synthesize cardNOValueLabel;

@synthesize nameLabel;
@synthesize whiteSycleBgIV      = _whiteSycleBgIV;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        PASelfInfo *selfInfo = [PADataCenter sharedInstance].selfInfo;
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:self.bounds];
        bgImageView.image = [UIImage imageNamed:@"home_background.png"];
        [self addSubview:bgImageView];
        
        CGFloat x, y, w, h;
        CGSize size = frame.size;
        CGFloat space = 10;
        
        w = h = 70;
        y = space;
        x = (size.width - w) / 2;
        
        self.whiteSycleBgIV = [[UIImageView alloc] initWithFrame:CGRectMake(x-3, y-3, w+7, h+7)];
        self.whiteSycleBgIV.backgroundColor = [UIColor clearColor];
        self.whiteSycleBgIV.image = [UIImage imageNamed:@"account_face.png"];
        [self addSubview:self.whiteSycleBgIV];
        
        
        self.headIV = [[PAAsynImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        self.headIV.defaultImg = [UIImage imageNamed:@"home_myphoto_non.png"];
        [self addSubview:self.headIV];
        [self.headIV setImgUrl:selfInfo.baseInfo.headImageUrl key:selfInfo.baseInfo.phoneNum digest:selfInfo.baseInfo.headImageDigest];
        
        if (!selfInfo.baseInfo.headImageUrl) {
            self.whiteSycleBgIV.hidden = YES;
            self.headIV.frame = CGRectMake(x-3, y-3, w+7, h+7);
        }else{
            self.whiteSycleBgIV.hidden = NO;
            self.headIV.frame = CGRectMake(x, y, w, h);
        }
        self.headIV.cornerRadius = self.headIV.frame.size.height/2;
        changePicButton = [UIButton buttonWithType:UIButtonTypeCustom];
        changePicButton.frame = CGRectMake(x, y, w, h);
        [changePicButton setBackgroundColor:[UIColor clearColor]];
        changePicButton.tag = 5;
        [changePicButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:changePicButton];
        
        w = h = 36;
        x = size.width - space - w;
        // 设置
        setButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        setButton.frame = CGRectMake(x, y, w, h);
        [setButton setBackgroundImage:[UIImage imageNamed:@"account_setting.png"] forState:UIControlStateNormal];
        [setButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
        setButton.tag = 4;
        [self addSubview:setButton];
        
        w = 100;
        x = (size.width - w) / 2 ;
        y = CGRectGetMaxY(self.headIV.frame);
        nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
        nameLabel.backgroundColor = [UIColor clearColor];
        nameLabel.textAlignment = UITextAlignmentCenter;
        nameLabel.font = [UIFont boldSystemFontOfSize:20.0];
        nameLabel.textColor = [UIColor whiteColor];
        nameLabel.text = @"郭伟坤";
        [self addSubview:nameLabel];
        
        w = 110;
        x = size.width / 2 - w -20;
        y = CGRectGetMaxY(nameLabel.frame);
        yueKeyLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
        yueKeyLabel.backgroundColor = [UIColor clearColor];
        yueKeyLabel.textAlignment = UITextAlignmentRight;
        yueKeyLabel.font = [UIFont systemFontOfSize:16.0];
        yueKeyLabel.textColor = [UIColor colorWithHexString:@"#ffffff"];
        yueKeyLabel.text = @"余额: ";
        [self addSubview:yueKeyLabel];
        
        yueValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(yueKeyLabel.frame), y, w +50, h)];
        yueValueLabel.backgroundColor = [UIColor clearColor];
        yueValueLabel.textAlignment = UITextAlignmentLeft;
        yueValueLabel.font = [UIFont systemFontOfSize:20.0];
        yueValueLabel.textColor = [UIColor orangeColor];
        yueValueLabel.text = @"99999元";
        [self addSubview:yueValueLabel];
        
        y = CGRectGetMaxY(yueKeyLabel.frame);
        cardNOKeyLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
        cardNOKeyLabel.backgroundColor = [UIColor clearColor];
        cardNOKeyLabel.textAlignment = UITextAlignmentRight;
        cardNOKeyLabel.font = [UIFont systemFontOfSize:16.0];
        cardNOKeyLabel.textColor = [UIColor whiteColor];
        cardNOKeyLabel.text = @"银行卡: ";
        cardNOKeyLabel.textColor = PERSONAL_COLOR;
        [self addSubview:cardNOKeyLabel];
        
        cardNOValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(cardNOKeyLabel.frame), y, w, h)];
        cardNOValueLabel.backgroundColor = [UIColor clearColor];
        cardNOValueLabel.textAlignment = UITextAlignmentLeft;
        cardNOValueLabel.font = [UIFont systemFontOfSize:20.0];
        cardNOValueLabel.textColor = [UIColor orangeColor];
        cardNOValueLabel.text = [NSString stringWithFormat:@"%d张",[selfInfo.bankCardInfos count]];
        [self addSubview:cardNOValueLabel];
        
        y = CGRectGetMaxY(cardNOValueLabel.frame) + 10;
        w = 300;
        h = 231;
        x = (size.width - w) / 2;
        
        boardImageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        boardImageView.image = [UIImage imageNamed:@"account_cards.png"];
        boardImageView.userInteractionEnabled = YES;
        [self addSubview:boardImageView];
        
        w = 125;
        h = 92/2;
        x = (CGRectGetWidth(boardImageView.frame) - 2 * w - space) / 2;
        y = CGRectGetHeight(boardImageView.frame) - h - space;
        rechargeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        rechargeButton.frame = CGRectMake(x, y, w, h);
        rechargeButton.backgroundColor = [UIColor clearColor];
        [rechargeButton setBackgroundImage:[UIImage imageNamed:@"home_chargeBT1.png"] forState:UIControlStateNormal];
        [rechargeButton setBackgroundImage:[UIImage imageNamed:@"home_chargeBT2.png"] forState:UIControlStateHighlighted];
        [rechargeButton setTitle:@"充值" forState:UIControlStateNormal];
        rechargeButton.titleLabel.textColor = PERSONAL_COLOR;
        rechargeButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
        [rechargeButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
        rechargeButton.tag = 1;
        [boardImageView addSubview:rechargeButton];
        
        x += (w + space);
        // 提现
        extractButton = [UIButton buttonWithType:UIButtonTypeCustom];
        extractButton.frame = CGRectMake(x, y, w, h);
        extractButton.backgroundColor = [UIColor clearColor];
        [extractButton setBackgroundImage:[UIImage imageNamed:@"home_chargeBT1.png"] forState:UIControlStateNormal];
        [extractButton setBackgroundImage:[UIImage imageNamed:@"home_chargeBT2.png"] forState:UIControlStateHighlighted];
        [extractButton setTitle:@"提现" forState:UIControlStateNormal];
        [extractButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
        extractButton.titleLabel.textColor = PERSONAL_COLOR;
        extractButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
        extractButton.tag = 2;
        [boardImageView addSubview:extractButton];
    }
    return self;
}

-(void)buttonActive:(id)sender
{
    [self.parentController testNext:sender];
}

- (void)refreshUIData
{
    PASelfInfo *selfInfo = [[PADataCenter sharedInstance] selfInfo];
    yueValueLabel.text = [NSString stringWithFormat:@"%@ 元", [NSString stringWithFormat:@"%.2f",selfInfo.availableBalance]];
    nameLabel.text = [[PADataCenter sharedInstance] selfInfo].baseInfo.realName;
}

- (void)loadBaseInfo:(PAUserInfo *)userInfo
{
    nameLabel.text = userInfo.realName;
    
}
- (void)loadBalance:(float)balance
{}

@end
